﻿#region License
// (c) Garry McGlennon 2009
// 
// This project is made available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// 
// View the project and the latest code at http://dnpframework.codeplex.com/
// 
// All other rights reserved.
// 
// blog: www.dotNetProfessional.com/blog/
#endregion
using System.Xml.Serialization;
using dnp.ServiceModel.Configuration;
using dnp.Framework.Scripting;

namespace dnp.ServiceModel
{
    public class ServiceMethodMetaData<T>
    {
        private readonly ServiceMethodMetaDataDefinitionCollection _definitions;
        private readonly dnpModel _model;
        private readonly T _source;
        private readonly ServiceFeatureEnum _serviceMethodFeature;

        public ServiceMethodMetaData(T source, ServiceFeatureEnum serviceMethodFeature, ServiceMethodMetaDataDefinitionCollection definitions, dnpModel model)
        {
            _definitions = definitions;
            _model = model;
            _source = source;
            _serviceMethodFeature = serviceMethodFeature;
        }

        [XmlAttribute]
        public ServiceFeatureEnum ServiceFeature
        {
            get { return _serviceMethodFeature; }
        }

        protected T Source
        {
            get { return _source; }
        }

        public dnpModel Model
        {
            get { return _model; }
        }

        public string FunctionName
        {
            get { return Naming.EvaluateNamingExpression(_definitions[this.ServiceFeature.ToString()].FunctionName,this.Source); }
        }

        public string StoredProcedureName
        {
            get { return Naming.EvaluateNamingExpression(_definitions[this.ServiceFeature.ToString()].StoredProcedureName, this.Source); }
        }

        public string MethodName
        {
            get { return Naming.EvaluateNamingExpression(_definitions[this.ServiceFeature.ToString()].MethodName, this.Source); }
        }

        public string Role
        {
            get { return _definitions[this.ServiceFeature.ToString()].Role; }
        }
    }
}
